import math
def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True
a=input().split()
s=0
words=['zero','one','two','three','four','five','six','seven','eight','nine']
if len(a)!=3:
    print("Wrong input")
else:
    for i in range(3):
        if a[i] not in words:
            print("Wrong input")
            break
    for i in range(10):
        if a[0]==words[i]:
            s=i*100
        if a[1]==words[i]:
            s+=i*10
        if a[2]==words[i]:
            s+=i
    if s >= 100:
        o = 0
        while True:
            o += 1
            if is_prime(s - o):
                print(s - o)
                break
            if is_prime(s + o):
                print(s + o)
                break
    else:
        print("Wrong input")
